/*******************************************************************************
Replication Materials for Blau, Kahn, Brummund, Cook, and Larson-Koester "Is 
There Still Son Preference in the United States?"

Table R4

Date Modified: 10/19/2019

*******************************************************************************/




*-------------------------------------------------------------------------------
                                   *LOAD DATA
*-------------------------------------------------------------------------------
use "$acs\acs_data", clear


*-------------------------------------------------------------------------------
                               *RESTRICT SAMPLE
*-------------------------------------------------------------------------------
keep if nonusbirth == 0 & multi_sample != 1 & mult == 0 & oldc <=12 & ///
	inrange(age,18,40)==1 & nchild18>=1
drop if citizen==1 | marst == 5

*-------------------------------------------------------------------------------
                               *AGE AT FIRST BIRTH
*-------------------------------------------------------------------------------
egen max_age = rowmax(c_age*)
sum max_age // should be 12
gen birthage = age - max_age

*-------------------------------------------------------------------------------
                          *GENERATE CORE AND EXTENDED SAMPLES
*-------------------------------------------------------------------------------
gen extended = 1
gen core = 0
replace core = 1 if nonrkids == 0 & nonusbirth == 0 & sfrelate == 0 & ///
	father_sample != 1 & multi_sample != 1 & mult == 0 & female == 1 & ///
	oldc <=12 & inrange(age,18,40)==1 & foster_hh == 0
	
*-------------------------------------------------------------------------------
                                  *REGRESSIONS
*-------------------------------------------------------------------------------
label var chld1 "First Child Girl"	
local controls "lths scol cold" //leave out: hsdi
local controls "`controls' i.genrace i.region i.year age age2 age3"	
local wgt_core "hhwtnorm"	
local wgt_ext "perwtnorm"

// CORE SAMPLE, NATIVE
reg femhdalt chld1 birthage `controls' if native == 1 & core == 1 [aw=`wgt_core'],  robust
return list
local b = round(r(table)[1, 1], 0.0001)
sum femhdalt if native == 1 & core == 1 [aw=`wgt_core']
local mean= round(r(mean), 0.0001)
local prct: display %5.4f 100*`b'/`mean'
outreg2 using "$routput\Table_R4", replace excel dec(4) addtext(Dep. Var. Mean, `mean', Pct Effects, `prct') ctitle(Core, Native) keep(chld1) label nocons nor2 ///
	title("Table R4: Table T1, Age at 1st Birth Ctrl")

// CORE SAMPLE, IMMIGRANTS
reg femhdalt chld1 birthage `controls' if native == 0 & core == 1 [aw=`wgt_core'],  robust
return list
local b = round(r(table)[1, 1], 0.0001)
sum femhdalt if native == 0 & core == 1 [aw=`wgt_core']
local mean = round(r(mean), 0.0001)
local prct: display %5.4f 100*`b'/`mean'
outreg2 using "$routput\Table_R4", append excel dec(4) addtext(Dep. Var. Mean, `mean', Pct Effects, `prct') ctitle(Core, Immigrant) keep(chld1) label nocons nor2

// CORE SAMPLE, BOTH
reg femhdalt chld1 birthage `controls' if core == 1 [aw=`wgt_core'],  robust
return list
local b = round(r(table)[1, 1], 0.0001)
sum femhdalt if core == 1 [aw=`wgt_core']
local mean = round(r(mean), 0.0001)
local prct: display %5.4f 100*`b'/`mean'
outreg2 using "$routput\Table_R4", append excel dec(4) addtext(Dep. Var. Mean, `mean', Pct Effects, `prct') ctitle(Core, Both) keep(chld1) label nocons nor2

// EXTENDED SAMPLE, NATIVE
reg femhdalt chld1 birthage `controls' if native == 1 & extended == 1 [aw=`wgt_ext'],  robust
return list
local b = round(r(table)[1, 1], 0.0001)
sum femhdalt if native == 1 & extended == 1 [aw=`wgt_ext']
local mean = round(r(mean), 0.0001)
local prct: display %5.4f 100*`b'/`mean'
outreg2 using "$routput\Table_R4", append excel dec(4) addtext(Dep. Var. Mean, `mean', Pct Effects, `prct') ctitle(Extended, Native) keep(chld1) label nocons nor2

// EXTENDED SAMPLE, IMMIGRANTS
reg femhdalt chld1 birthage `controls' if native == 0 & extended == 1 [aw=`wgt_ext'],  robust
return list
local b = round(r(table)[1, 1], 0.0001)
sum femhdalt if native == 0 & extended == 1 [aw=`wgt_ext']
local mean = round(r(mean), 0.0001)
local prct: display %5.4f 100*`b'/`mean'
outreg2 using "$routput\Table_R4", append excel dec(4) addtext(Dep. Var. Mean, `mean', Pct Effects, `prct') ctitle(Extended, Immigrant) keep(chld1) label nocons nor2

// EXTENDED SAMPLE, BOTH
reg femhdalt chld1 birthage `controls' if extended == 1 [aw=`wgt_ext'],  robust
return list
local b = round(r(table)[1, 1], 0.0001)
sum femhdalt  if extended == 1 [aw=`wgt_ext']
local mean = round(r(mean), 0.0001)
local prct: display %5.4f 100*`b'/`mean'
outreg2 using "$routput\Table_R4", append excel dec(4) addtext(Dep. Var. Mean, `mean', Pct Effects, `prct') ctitle(Extended, Both) keep(chld1) label nocons nor2
	
	
	
	